using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.ComponentModel.Design;

namespace Widgetsphere.Generator.Design.Editors
{
	internal class RowEntryCollectionEditor : System.Drawing.Design.UITypeEditor
	{
		public RowEntryCollectionEditor()
		{
		}

		public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
		{
			return System.Drawing.Design.UITypeEditorEditStyle.Modal;
		}

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
      try
      {
        System.Windows.Forms.Design.IWindowsFormsEditorService edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
        Widgetsphere.Generator.Models.Table table = (Widgetsphere.Generator.Models.Table)context.Instance;
        Widgetsphere.Generator.Forms.RowEntryCollectionForm F = new Widgetsphere.Generator.Forms.RowEntryCollectionForm(table);
        if(edSvc.ShowDialog(F) == System.Windows.Forms.DialogResult.OK)
        {
          table.Root.Dirty = true;
          context.OnComponentChanged();
        }
      }
      catch(Exception ex) { }
      return value;
    }

	}
}
